package com.neusoft.neu24.myaspect.aops;


import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Service;


@Service
@Aspect
public class QieMian {

    public  static  int index = 0;

    @Pointcut("execution(*   com.neusoft.neu24.myaspect.service.*.*(..)  )")
    private void allMethods(){}

    @Around("allMethods()")
    public Object around( ProceedingJoinPoint joinPoint  ) throws   Throwable {
        System.out.println("QieMian.around ----  > 前置通知");
        Object retVal =  null;
        try {
            retVal =  joinPoint.proceed();
        }catch (Exception  ex ){
            System.out.println(ex.getMessage());
        }
        System.out.println("QieMian.around  -----  > 返回通知");
        System.out.println(retVal);
        return  retVal;
    }



//    如果连接点方法没有异常
//    @AfterReturning( pointcut = "allMethods()" , returning = "retval")
    public void fanhHuiTongzhi( Object retval ){
        System.out.println(retval);
        System.out.println("QieMian.fanhHuiTongzhi");
    }

//    @AfterThrowing(pointcut = "allMethods()" ,throwing="ex")
    public void afterThrowing(  ArithmeticException  ex   ){
        System.out.println(ex.getMessage());
        System.out.println("QieMian.afterThrowing");
    }

//    最终通知
//    @After("allMethods()")

    public  void after(){
        System.out.println("QieMian.after");
    }


    @Before("allMethods()")
    public void qianZhiTongzhi1(){
        System.out.println("QieMian.qianZhiTongzhi2222222222222222222");
    }
//    @Before("allMethods()")
    public void qianZhiTongzhi(){
//        ThreadLocal<String> threadLocal =new ThreadLocal<>();
        index++;
//        前置通知一定会执行
        System.out.println("前置通知1111111111111111");
// 前置通知执行后，不再继续执行的方法是抛出异常
//        int  i =1;
//        int j = 0 ;
//        i =  i / j ;
    }


}
